Fixed a breaking change and added tests for that case.
authorKalita Alexey <kalita.alexey@outlook.com>
Sat, 11 Feb 2017 08:21:02 +0000 (11:21 +0300)
committerKalita Alexey <kalita.alexey@outlook.com>
Sat, 11 Feb 2017 08:21:02 +0000 (11:21 +0300)
src/cargo/core/manifest.rs
tests/metadata.rs

index 3f95edee4a6a5124ad27d0e7b2f82885c7cf7d4b..d17b787fe982b62bc62c39e45507183ff5cd0524 100644 (file)
@@ -113,18 +113,21 @@ pub enum TargetKind {
 }
 
 impl TargetKind {
-    pub fn name(&self) -> &'static str {
+    /// Returns a vector of crate types as specified in a manifest with one difference.
+    /// For ExampleLib it returns "example" instead of crate types
+    pub fn kinds(&self) -> Vec<&str> {
         use self::TargetKind::*;
         match *self {
-            Lib(_) => "lib",
-            Bin => "bin",
-            ExampleBin | ExampleLib(_) => "example",
-            Test => "test",
-            CustomBuild => "custom-build",
-            Bench => "bench"
+            Lib(ref kinds) => kinds.iter().map(LibKind::crate_type).collect(),
+            Bin => vec!["bin"],
+            ExampleBin | ExampleLib(_) => vec!["example"],
+            Test => vec!["test"],
+            CustomBuild => vec!["custom-build"],
+            Bench => vec!["bench"]
         }
     }
 
+    /// Returns a vector of crate types as specified in a manifest
     pub fn crate_types(&self) -> Vec<&str> {
         use self::TargetKind::*;
         match *self {
@@ -216,7 +219,7 @@ struct SerializedTarget<'a> {
 impl Encodable for Target {
     fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
         SerializedTarget {
-            kind: vec![self.kind.name()],
+            kind: self.kind.kinds(),
             crate_types: self.kind.crate_types(),
             name: &self.name,
             src_path: &self.src_path.display().to_string(),
index 07dc4bbec4d7875754ccebf50a38c1f05c7bd2e7..f7dbbc414f10e2d14d42e6192b44a6f9e1ae4010 100644 (file)
@@ -53,6 +53,62 @@ fn cargo_metadata_simple() {
     }"#));
 }
 
+#[test]
+fn library_with_several_crate_types() {
+    let p = project("foo")
+            .file("src/lib.rs", "")
+            .file("Cargo.toml", r#"
+[package]
+name = "foo"
+version = "0.5.0"
+
+[lib]
+crate-type = ["lib", "staticlib"]
+            "#);
+
+    assert_that(p.cargo_process("metadata"), execs().with_json(r#"
+    {
+        "packages": [
+            {
+                "name": "foo",
+                "version": "0.5.0",
+                "id": "foo[..]",
+                "source": null,
+                "dependencies": [],
+                "license": null,
+                "license_file": null,
+                "description": null,
+                "targets": [
+                    {
+                        "kind": [
+                            "lib",
+                            "staticlib"
+                        ],
+                        "crate_types": [
+                            "lib",
+                            "staticlib"
+                        ],
+                        "name": "foo",
+                        "src_path": "[..][/]foo[/]src[/]lib.rs"
+                    }
+                ],
+                "features": {},
+                "manifest_path": "[..]Cargo.toml"
+            }
+        ],
+        "workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
+        "resolve": {
+            "nodes": [
+                {
+                    "dependencies": [],
+                    "id": "foo 0.5.0 (path+file:[..]foo)"
+                }
+            ],
+            "root": "foo 0.5.0 (path+file:[..]foo)"
+        },
+        "version": 1
+    }"#));
+}
 
 #[test]
 fn cargo_metadata_with_deps_and_version() {
@@ -567,7 +623,7 @@ fn cargo_metadata_no_deps_cwd() {
 }
 
 #[test]
-fn carg_metadata_bad_version() {
+fn cargo_metadata_bad_version() {
     let p = project("foo")
         .file("Cargo.toml", &basic_bin_manifest("foo"))
         .file("src/foo.rs", &main_file(r#""i am foo""#, &[]));